package fr.vvins.core.services;

import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.PathSegment;

import fr.vvins.core.biz.exception.BizException;
import fr.vvins.core.biz.search.dto.SearchFacetResultDto;
import fr.vvins.core.biz.search.dto.SearchResultDto;
import fr.vvins.core.biz.search.dto.SuggestResultDto;
import fr.vvins.core.common.TechnicalException;

/**
 * Search service interface expose all methods for browse catalog.
 * @author fguay
 *
 */

public interface SearchService {

	/**
	 * Suggest a results link to word param.<BR>
	 * Method : GET<BR>
	 * Path : "/search/suggest/{word}"<BR>
	 * Produces : MediaType.APPLICATION_JSON<BR>
	 * 
	 * @param word : search this word
	 * @return
	 * @throws TechnicalException
	 * @throws BizException
	 */
	@GET
	@Path("/suggest/{word}")
	@Produces(MediaType.APPLICATION_JSON)
	public SuggestResultDto suggest(@PathParam("word") String word) throws TechnicalException, BizException;

	/**
	 * Suggest a results link to word and entity.<BR>
	 * Method : GET<BR>
	 * Path : "/search/suggest/type/{entity}/{word}"<BR>
	 * Produces : MediaType.APPLICATION_JSON<BR>
	 * 
	 * @param entity : type of entity
	 * @param word : search this word
	 * @return
	 * @throws TechnicalException
	 * @throws BizException
	 */
	@GET
	@Path("/suggest/type/{entity}/{word}")
	@Produces("application/json")
	public SuggestResultDto suggestEntity(@PathParam("entity") String entity,@PathParam("word") String word) throws TechnicalException, BizException;
	
	/**
	 * Search a specific word in all entity.<BR>
	 * Method : GET<BR>
	 * Path : "/search/find/{word}"<BR>
	 * Produces : MediaType.APPLICATION_JSON<BR>
	 * 
	 * @param word : search this word
	 * @return
	 * @throws TechnicalException
	 * @throws BizException
	 */
	@GET
	@Path("/find/{word}")
	@Produces("application/json")
	public SearchResultDto find(@PathParam("word") String word) throws TechnicalException, BizException;

	/**
	 * Find all entity according word and facets filter.<BR>
	 * Method : GET<BR>
	 * Path : "/search/find/{word}/facets/{facetsLimit:.*}?facets={facets,*}"<BR>
	 * Produces : MediaType.APPLICATION_JSON<BR>
	 * 
	 * @param word : search this word
	 * @param facets : list of facet keys
	 * @param facetsLimit : limit facet results
	 * @param facetsRange : limit facet in range of results
	 * @return
	 * @throws TechnicalException
	 * @throws BizException
	 */
	@GET
	@Path("/find/{word}/facets/{facetsLimit:.*}")
	@Produces("application/json")
	public SearchFacetResultDto find(@PathParam("word") String word, @QueryParam("facets") String facets, @PathParam("facetsLimit") List<PathSegment> facetsLimit, @QueryParam("facetsRange") String facetsRange) throws TechnicalException, BizException;

	/**
	 * Find all entity according facet filter.<BR>
	 * Method : GET<BR>
	 * Path : "/search/find/facets/{facetsLimit:.*}?facets={facets,*}"<BR>
	 * Produces : MediaType.APPLICATION_JSON<BR>
	 * 
	 * @param facets : list of facet keys
	 * @param facetsLimit : limit facet results
	 * @param facetsRange : limit facet in range of results
	 * @return
	 * @throws TechnicalException
	 * @throws BizException
	 */
	@GET
	@Path("/find/facets/{facetsLimit:.*}")
	@Produces("application/json")
	public SearchFacetResultDto find( @QueryParam("facets") String facets, @PathParam("facetsLimit") List<PathSegment> facetsLimit, @QueryParam("facetsRange") String facetsRange) throws TechnicalException, BizException;
	
	/**
	 * Search specific entity according a word.<BR>
	 * Method : GET<BR>
	 * Path : "/search/find/type/{entity}/{word}"<BR>
	 * Produces : MediaType.APPLICATION_JSON<BR>
	 * 
	 * @param entity : type of entity
	 * @param word : search this word
	 * @return
	 * @throws TechnicalException
	 * @throws BizException
	 */
	@GET
	@Path("/find/type/{entity}/{word}")
	@Produces("application/json")
	public SearchResultDto findEntity(@PathParam("entity") String entity, @PathParam("word") String word) throws TechnicalException, BizException;

	/**
	 * Search specific entity according word and filter results by facet.<BR>
	 * Method : GET<BR>
	 * Path : "/search/find/type/{entity}/{word}/facets/{facetsLimit:.*}?facets={facets,*}"<BR>
	 * Produces : MediaType.APPLICATION_JSON<BR>
	 * 
	 * @param entity : type of entity
	 * @param word : search this word
	 * @param facets : list of facet keys
	 * @param facetsLimit : limit facet results
	 * @param facetsRange : limit facet in range of results
	 * @return
	 * @throws TechnicalException
	 * @throws BizException
	 */
	@GET
	@Path("/find/type/{entity}/{word}/facets/{facetsLimit:.*}")
	@Produces("application/json")
	public SearchFacetResultDto findEntity(@PathParam("entity") String entity, @PathParam("word") String word, @QueryParam("facets") String facets, @PathParam("facetsLimit") List<PathSegment> facetsLimit, @QueryParam("facetsRange") String facetsRange) throws TechnicalException, BizException;

	/**
	 * Find specific entity and filter by facets.<BR>
	 * Method : GET<BR>
	 * Path : "/search/find/type/{entity}/facets/{facetsLimit:.*}?facets={facets,*}"<BR>
	 * Produces : MediaType.APPLICATION_JSON<BR>
	 * 
	 * @param entity : type of entity
	 * @param facets : list of facet keys
	 * @param facetsLimit : limit facet results
	 * @param facetsRange : limit facet in range of results
	 * @return
	 * @throws TechnicalException
	 * @throws BizException
	 */
	@GET
	@Path("/find/type/{entity}/facets/{facetsLimit:.*}")
	@Produces("application/json")
	public SearchFacetResultDto findEntity(@PathParam("entity") String entity, @QueryParam("facets") String facets, @PathParam("facetsLimit") List<PathSegment> facetsLimit, @QueryParam("facetsRange") String facetsRange) throws TechnicalException, BizException;

}
